package com.imti.animationdemo;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView()
    {
        ImageView alphaAnimImage = findViewById(R.id.image_alpha_anim);
        ImageView scaleAnimImage = findViewById(R.id.image_scale_anim);
        ImageView translateAnimImage = findViewById(R.id.image_translate_anim);

        //所有补间动画的父类为Animation
        Animation alpha =
            AnimationUtils.loadAnimation(this, R.anim.anim_alpha);

        alphaAnimImage.setAnimation(alpha);

        //缩放动画
        scaleAnimImage.setAnimation(
            AnimationUtils.loadAnimation(this, R.anim.anim_scale));

        //位移动画
        translateAnimImage.setAnimation(
            AnimationUtils.loadAnimation(this, R.anim.anim_translate));

        //所有的动画都有对应的类，可以通过Java直接new出动画对象，并动态设置参数
        TranslateAnimation translateAnimation = new TranslateAnimation(
            0f, 0f, 200f, 200f);

        //与Animation的属性android:fillAfter相同
        //用于设置动画停留在结束位置
        translateAnimation.setFillAfter(true);
    }
}